package org.wmq.housewebadmin.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.wmq.housemodel.entity.Label;
import org.wmq.housemodel.entity.Result;
import org.wmq.housewebadmin.mapper.LabelMapper;
import org.wmq.housewebadmin.service.LabelService;

import java.util.List;

@Service
@RequiredArgsConstructor
public class LabelServiceImpl implements LabelService {
    private final LabelMapper labelMapper;

    @Override
    public List<Label> getList(Integer type) {
        return this.labelMapper.selectAll(type);
    }

    @Override
    public Result<Void> saveOrUpdate(Label label) {
        if (label.getId() == null){
            if (this.labelMapper.insert(label) == 0){
                return Result.error("id已存在");
            }else{
                return Result.ok();
            }
        }else{
            if(this.labelMapper.insert(label) == 0){
                return Result.error("id不存在");
            }else{
                return Result.ok();
            }
        }
    }

    @Override
    public boolean deleteById(Long id) {
        Label label = new Label();
        label.setId(id);
        return this.labelMapper.deleteById(label) == 1;
    }

}
